<?php

namespace app\model;
use app\util\Tools;
class User extends Base
{
    protected $autoWriteTimestamp = true;
    protected $resultSetType = 'collection';
    protected $updateTime = 'updataTime';
    protected $createTime = 'addTime';

    public function userProgram() {
        return $this->hasOne('UserProgram','userID','userID')
            ->field('userProgramID,userID,agentId,parentID,VIP,earnings,beans');
    }

    public function getSexAttr($value) {
        $sex = ['0' => '未知','1' => '男','2' => '女'];
        return $sex[$value];
    }

    public function getBeansAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setBeansAttr($value){
        return $value * 100;
    }


    public function getNicknameAttr($value){
        return emoji_decode($value);
    }

    public function setNicknameAttr($value){
        return emoji_encode($value);
    }

    public function getStatusTextAttr($value, $data) {
        $status = ['0' => '冻结','1' => '正常', '2' => '冻结'];
        return isset($status[$data['status']])?$status[$data['status']]:'未知';
    }

    public function getcheckStatusTextAttr($value,$data) {
        $status = ['-1' => '审核中','1' => '通过', '2' => '驳回'];
        return isset($status[$data['statusCheck']])?$status[$data['statusCheck']]:'未知';
    }

    public function platformData(){
        return $this->hasOne('platform','id','type')->field('id,name');
    }

   public function getisAllotTextAttr($value, $data) {
       $isAllot = ['1' => '已分配','2' => '用户异常', '9' => '未分配'];
       return isset($isAllot[$data['isAllot']]) ? $isAllot[$data['isAllot']]: '未知';
   }

    public function getmoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setmoneyAttr($value){
        return $value * 100;
    }

    public function gettotalMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function settotalMoneyAttr($value){
        return $value * 100;
    }

    public function getwithdrawMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setwithdrawMoneyAttr($value){
        return $value * 100;
    }
}
